package com.example.springboot.mapper;

import com.example.springboot.entity.Companies;

import com.example.springboot.entity.jobs;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface JobMangerMapper {

    @Select("select * from jobs")
    List<jobs> findAll();

    @Select("SELECT * FROM jobs WHERE job_title LIKE CONCAT('%', #{job_title}, '%')")
    List<jobs> selectByTitle(String job_title);

    @Select("SELECT * from companies where company_id=#{company_id}")
    List<Companies> selectByCompany_id(int company_id);

    @Update("UPDATE jobs SET job_title=#{job_title}, job_description=#{job_description}, requirements=#{requirements}, location=#{location},salary=#{salary} WHERE job_id=#{job_id}")
    void editUserByJob_id(jobs jobs);

    @Delete("DELETE FROM jobs WHERE job_id=#{job_id}")
    void deleteJob(int job_id);

    @Delete("DELETE FROM applications WHERE job_id=#{job_id}")
    void deleteJobA(int job_id);

    @Delete({
            "<script>",
            "DELETE FROM jobs WHERE job_id IN ",
            "<foreach item='job_id' collection='list' open='(' separator=',' close=')'>#{job_id}</foreach>",
            "</script>"
    })
    void deleteJobBatch(List<Long> ids);

    @Delete({
            "<script>",
            "DELETE FROM applications WHERE job_id IN ",
            "<foreach item='job_id' collection='list' open='(' separator=',' close=')'>#{job_id}</foreach>",
            "</script>"
    })
    void deleteJobBatchA(List<Long> ids);
}
